home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog5.arj / NOMULTI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  1.3 KB  |  57 lines

  1. { nomulti.pas -- Prevent multiple application instances }
  2.  
  3. program NoMulti;
  4.  
  5. uses WinTypes, WinProcs, WObjects;
  6.  
  7. type
  8.  
  9.   MultiApplication = object(TApplication)
  10.     FirstInstance: Boolean;
  11.     constructor Init(AName: PChar);
  12.     procedure InitMainWindow; virtual;
  13.     procedure InitApplication; virtual;
  14.   end;
  15.  
  16. {- Initialize firstInstance data field }
  17. constructor MultiApplication.Init(AName: PChar);
  18. begin
  19.   TApplication.Init(AName);
  20.   FirstInstance := false
  21. end;
  22.  
  23. {- Called to initialize first instance only }
  24. procedure MultiApplication.InitApplication;
  25. begin
  26.   FirstInstance := true
  27. end;
  28.  
  29. {- Initialize the application's window }
  30. procedure MultiApplication.InitMainWindow;
  31. begin
  32.   if FirstInstance then
  33.     MainWindow:= New(PWindow, Init(nil, 'First Instance'))
  34.   else begin
  35.     MessageBox(0, 'Multiple Instances Not Allowed',
  36.       'Application Error', mb_TaskModal or mb_IconExclamation);
  37.     Halt(0)
  38.   end
  39. end;
  40.  
  41. var
  42.  
  43.   MultiApp: MultiApplication;
  44.  
  45. begin
  46.   MultiApp.Init('Multi');
  47.   MultiApp.Run;
  48.   MultiApp.Done
  49. end.
  50.  
  51.  
  52. { --------------------------------------------------------------
  53.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  54.   Revision 1.00    Date: 1/24/1991
  55.   ------------------------------------------------------------- }
  56.  
  57.